package com.iot.gateway.aspectj.converter;

import com.iot.gateway.annotation.FieldConverter;

import java.util.Set;

/**
 * 字符串转Boolean
 */
public class BooleanConverter implements FieldConverter {

    private static final Set<String> TRUE_VALUES = Set.of("true", "yes", "1", "on");
    private static final Set<String> FALSE_VALUES = Set.of("false", "no", "0", "off");

    @Override
    public Object convert(Object value) {
        if (value instanceof String) {
            String strVal = ((String) value).trim().toLowerCase();
            return TRUE_VALUES.contains(strVal);
        }
        return Boolean.parseBoolean(value.toString());
    }

}
